//
// Created by Administrator on 2022/1/29.
//

#include "myTestSample.h"
#include "Calculator.h"

myTestSample::myTestSample()
{
    cout << "new.ing a test sample" << endl;
}
myTestSample::~myTestSample()
{
    cout << "deleting a test sample" << endl;
}

void myTestSample::doSpeak( annimal &annimal )
{
    annimal.speak();
}

void myTestSample::test02( annimal &ann )
{
    cout << "size of annimal class = " << sizeof( ann ) << endl;
}
/*
 * 测试计算器
 * */
void myTestSample::test03(void)
{
    Calculator c;
    c.m_Num1 = 1;
    c.m_Num2 = 2;

    cout << c.m_Num1 << "+" << c.m_Num2 << \
        "=" << c.getResult("+") << endl;

}

/*
 * 测试多态写法计算器
 * */
void myTestSample::test04( void )
{
    //AbstractCalculator2 *abc = new AddCalculator;   // 父类指向子类，已经发生了多态
    AbstractCalculator2 *abc = new SubCalculator;   // 父类指向子类，已经发生了多态
    // 加法运算
    abc->m_Num1 = 1;
    abc->m_Num2 = 2;

    cout << abc->m_Num1 << "op" << abc->m_Num2 << \
        "=" << abc->getResult2() << endl;

    delete abc;

}

void myTestSample::test05(void) {
    Coffee coffee;
    coffee.makeDrinking();

    Tea *tea = new Tea;
    tea->makeDrinking();

    dowork( coffee );
    dowork( *tea );

    delete tea;
}


void myTestSample::dowork(AbstractDringking &abs)
{
    abs.makeDrinking();
}